﻿using ReporterEngine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Xml.Linq;

namespace ReportEngine_TestProject
{
    
    
    /// <summary>
    ///This is a test class for WordReportEngineTest and is intended
    ///to contain all WordReportEngineTest Unit Tests
    ///</summary>
    [TestClass()]
    public class WordReportEngineTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Report
        ///</summary>
        [TestMethod()]
        public void ReportTest()
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var actualPath = assembly.GetManifestResourceNames();

            XDocument template = null;

            using (var str = assembly.GetManifestResourceStream("ReportEngine_TestProject.data.tpl1.docx"))
            {
                template = ReportPackage.GetTestDocumentFile(str);
            }

            var cifModel = utils.GetSampleModel();

            var targs = WordReportEngine.CreateArgs();

            targs.CurrentDesign = template.Root;

            WordReportEngine re = new WordReportEngine();
            re.Model = cifModel;

            var validationResult = re.ValidateSections(template.Root.Value);

            re.Report(targs);
            //template.Root.

            //var sections = targs.CurrentDesign.Descendants().

            Assert.AreEqual("","","invalid count of sections");
          
        }

        /// <summary>
        ///A test for Report
        ///</summary>
        [TestMethod()]
        public void Report2Test()
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var actualPath = assembly.GetManifestResourceNames();

            XDocument template = null;

            using (var str = assembly.GetManifestResourceStream("ReportEngine_TestProject.data.tpl2.docx"))
            {
                template = ReportPackage.GetTestDocumentFile(str);
            }

            var cifModel = utils.GetSampleModel();

            var targs = WordReportEngine.CreateArgs();

            targs.CurrentDesign = template.Root;

            WordReportEngine re = new WordReportEngine();
            re.Model = cifModel;

            var validationResult = re.ValidateSections(template.Root.Value);

            re.Report(targs);
            //template.Root.

            var msgs = ReportManager.DebugLog;
            var msglen = msgs.Length;

            //var sections = targs.CurrentDesign.Descendants().

            Assert.AreEqual("", "", "invalid count of sections");

        }

        /// <summary>
        ///A test enter inside text values for Report
        ///</summary>
        [TestMethod()]
        public void ReportEnterTest()
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var actualPath = assembly.GetManifestResourceNames();

            XDocument template = null;

            using (var str = assembly.GetManifestResourceStream("ReportEngine_TestProject.data.tplenter.docx"))
            {
                template = ReportPackage.GetTestDocumentFile(str);
            }

            var cifModel = utils.GetSampleModel();

            var targs = WordReportEngine.CreateArgs();
            
            targs.CurrentData = cifModel.GetNotebookQuery();

            targs.CurrentDesign = template.Root;
            

            WordReportEngine re = new WordReportEngine();
            re.ReportSettings = new ReportSettingsArgs();
            re.Model = cifModel;

            var validationResult = re.ValidateSections(template.Root.Value);

            re.Report(targs);
            //template.Root.

            //var sections = targs.CurrentDesign.Descendants().

            Assert.AreEqual("", "", "invalid count of sections");

        }

        /// <summary>
        ///A test error inside text values for Report
        ///</summary>
        [TestMethod()]
        public void ReportErrorTest()
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var actualPath = assembly.GetManifestResourceNames();

            XDocument template = null;

            using (var str = assembly.GetManifestResourceStream("ReportEngine_TestProject.data.tplerror.docx"))
            {
                template = ReportPackage.GetTestDocumentFile(str);
            }

            var cifModel = utils.GetSampleModel();

            var targs = WordReportEngine.CreateArgs();

            targs.CurrentData = cifModel.GetNotebookQuery();

            targs.CurrentDesign = template.Root;


            WordReportEngine re = new WordReportEngine();
            re.ReportSettings = new ReportSettingsArgs();
            re.Model = cifModel;

            var validationResult = re.ValidateSections(template.Root.Value);

            re.Report(targs);
            //template.Root.

            //var sections = targs.CurrentDesign.Descendants().

            Assert.AreEqual("", "", "invalid count of sections");

        }

        /// <summary>
        ///A test for SplitTextNodesIntoFirst
        ///</summary>
        [TestMethod()]
        public void SplitTextNodesIntoFirstTest()
        {
            XElement element = utils.getTemplate("splittpl1");

            int start = 86; // TODO: Initialize to an appropriate value
            int end = 103; // TODO: Initialize to an appropriate value
            
            bool dontRemoveP = false; // TODO: Initialize to an appropriate value

            var originalText = element.Value.Substring(start, end - start);
            WordReportEngine.SplitTextNodesIntoFirst(element, start, end, dontRemoveP);
            var validateText = element.Value.Substring(start, end - start);

            Assert.AreEqual(originalText, validateText, "invalid split function");

            //Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
    }
}
